import { getMd5Sign } from '../../utils/util'

const request = require('../config/index')

/**
 * 充值 此接口用于我的钱包充值金额 用于保证金不足时手工充值到足够，每个用户充值间隔至少为2分钟。
 * @param money
 */
export const topUp = (money: number) => {
    const body = {
        API_Model: 'Pay',
        API_Name: 'Driver_Pay',
        Data: {
            money
        }
    }

    const md5Res = getMd5Sign(body)

    return new Promise((resolve, reject) => {
        request
            .post(`/api/doAPI`, body, {
                sign: md5Res
            })
            .then((res: any) => {
                resolve(res)
            })
            .catch((err: any) => {
                reject(err)
            })
    })
}

/**
 * 提现
 */
export const withdraw = (money: number) => {
    const body = {
        API_Model: 'Money',
        API_Name: 'Withdrawal',
        Data: {
            money //提现金额
        }
    }

    const md5Res = getMd5Sign(body)

    return new Promise((resolve, reject) => {
        request
            .post(`/api/doAPI`, body, {
                sign: md5Res
            })
            .then((res: any) => {
                resolve(res)
            })
            .catch((err: any) => {
                reject(err)
            })
    })
}

/**
 * 获取明细
 */
export const getMoneyDetails = (page = 1, size = 3) => {
    const body = {
        API_Model: 'Money',
        API_Name: 'Search_User_Wallet_Detail',
        Data: {
            user_id: '', //用户ID 非管理员用户请求时可以不传
            page, //分页页码，数字类型
            size //一页多少条
        }
    }
    const md5Res = getMd5Sign(body)

    return new Promise((resolve, reject) => {
        request
            .post(`/api/doAPI`, body, {
                sign: md5Res
            })
            .then((res: any) => {
                resolve(res)
            })
            .catch((err: any) => {
                reject(err)
            })
    })
}

/**
 * 获取用户余额
 */
export const getBalance = () => {
    const body = {
        API_Model: 'Money',
        API_Name: 'Get_User_Wallet',
        Data: {
            page: '1', //分页页码，数字类型
            size: '10',
            user_name: '', //用户姓名 管理员请求时的筛选条件 司机请求传值无意义
            user_tel: '', //用户电话 管理员请求时的筛选条件 司机请求传值无意义
            user_idcard: '', //用户身份证 管理员请求时的筛选条件 司机请求传值无意义
            user_address: '', //用户地址 管理员请求时的筛选条件 司机请求传值无意义
            user_Sex: '' //用户性别 管理员请求时的筛选条件 司机请求传值无意义
        }
    }
    const md5Res = getMd5Sign(body)

    return new Promise((resolve, reject) => {
        request
            .post(`/api/doAPI`, body, {
                sign: md5Res
            })
            .then((res: any) => {
                resolve(res)
            })
            .catch((err: any) => {
                reject(err)
            })
    })
}

/**
 * 加盟
 * @param info
 */
export const driverJoining = (info: any) => {
    let body = {
        API_Model: 'DriverPeople',
        API_Name: 'Join_Driver',
        Data: {
            user_id: info.user_id, //司机用户ID
            car_id: info.car_id, //车型ID
            Driver_Number: info.Driver_Number, //驾驶证编号
            Car_Number: info.Car_Number, //行驶证编号
            Car_model: info.Car_model, //车型
            Car_vin: info.Car_vin, //车辆识别代号
            Car_record: info.Car_record, //车牌
            Car_register_date: info.Car_register_date, //行驶证注册日期
            Car_issue_date: info.Car_issue_date, //行驶证发证日期
            Driver_valid_from: info.Driver_valid_from, //驾驶证有效期开始日期
            Driver_valid_to: info.Driver_valid_to, //驾驶证有效期截止日期
            Car_engine_num: info.Car_engine_num, //发动机号码
            Car_passengers_num: info.Car_passengers_num, //核定载客数
            Car_use_character: info.Car_use_character, //车辆使用性质
            Driver_Photo_Url: info.Driver_Photo_Url, //驾驶证照片(调用通用上传地址号后得到的地址)
            Car_Photo_Url: info.Car_Photo_Url //行驶证照片(调用通用上传地址号后得到的地址)
        }
    }

    const md5Res = getMd5Sign(body)

    return new Promise((resolve, reject) => {
        request
            .post(`/api/doAPI`, body, {
                sign: md5Res
            })
            .then((res: any) => {
                resolve(res)
            })
            .catch((err: any) => {
                reject(err)
            })
    })
}
